package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.DataCenterService;
import com.yixun.qfbao.apidto.OrganSalePerformancePageListReqDto;
import com.yixun.qfbao.apidto.OrganSalePerformancePageListResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.PartnerInfo;
import com.yixun.qfbao.util.exception.TServerException;
import com.yixun.qfbao.utils.LoginUtils;
import com.yixun.qfbao.vo.OrganSalePerformancePageListReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class OrganSalePerformancePageListHander extends CommonAbstractHander {

    private static final Logger logger = LoggerFactory.getLogger(OrganSalePerformancePageListHander.class);

    @Autowired
    private DataCenterService dataCenterService;
    @Autowired
    private LoginUtils loginUtils;

    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO baseRequestDTO) {
        OrganSalePerformancePageListReqVo reqVo = (OrganSalePerformancePageListReqVo) baseRequestDTO;
        OrganSalePerformancePageListReqDto reqDto = reqVo.getParams();
        BaseResponseDTO<OrganSalePerformancePageListResDto> res = new BaseResponseDTO<>();

        PartnerInfo pi = loginUtils.getUser(reqDto.getUserId());
        if (pi == null) {
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("未获取到用户信息！");
            return res;
        }
        reqDto.setHigherId(pi.getHigherid());
        try {
            OrganSalePerformancePageListResDto resDto = dataCenterService.organSalePerformancePageList(reqDto);
            res.setResult(resDto.getResult());
            res.setResData(resDto);
        } catch (TServerException e) {
            logger.error("t server exception error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg(e.getErrorMsg());
        } catch (Exception e) {
            logger.error("OrganSalePerformancePageListHander error: {}", e);
            res.setResult(ResultEnum.FAIL.getNo());
            res.setErrorMsg("系统异常，请稍后再试！");
        }

        return res;
    }
}
